<template>
	<view class="information">
		<u-form :model="form" ref="uForm" v-if="account_type=='工人'">
			<u-form-item label="工种类型:" label-width='100px'>
				<u-input v-model="form.type_of_work" input-align="right" placeholder="请选择" type="select"
					@click="type_show=true" />
				<u-picker mode="selector" v-model="type_show"  :default-selector="[0]" :range="type_list" range-key="label" @confirm="confirm_type"></u-picker>
			</u-form-item>
			<u-form-item label="工种:" label-width='100px'>
				<u-input v-model="form.types_of_workers" input-align="right" placeholder="请选择" type="select"
					@click="workers_show=true" />
				<u-picker mode="selector" v-model="workers_show"  :default-selector="[0]" :range="workers_list" range-key="label" @confirm="confirm_workers"></u-picker>
			</u-form-item>
			<u-form-item label="工龄:" label-width='100px' class="isshow">
				<u-input input-align="right" v-model="form.working_years" type='number' />
			</u-form-item>
			<u-form-item label="性别:" label-width='100px'>
				<u-input v-model="form.sex" input-align="right" placeholder="请选择" type="select"
					@click="sex_show=true" />
				<u-picker mode="selector" v-model="sex_show"  :default-selector="[0]" :range="sex_list" range-key="label" @confirm="confirm_sex"></u-picker>
			</u-form-item>
			<u-form-item label="民族:" label-width='100px'>
				<u-input v-model="form.nation" input-align="right" placeholder="请选择" type="select"
					@click="nation_show=true" />
				<u-picker mode="selector" v-model="nation_show"  :default-selector="[0]" :range="nation_list" range-key="label" @confirm="confirm_nation"></u-picker>
			</u-form-item>
			<u-form-item label="文化程度:" label-width='100px'>
				<u-input v-model="form.degree_of_education" input-align="right" placeholder="请选择" type="select"
					@click="education_show=true" />
				<u-picker mode="selector" v-model="education_show"  :default-selector="[0]" :range="education_list" range-key="label" @confirm="confirm_education"></u-picker>
			</u-form-item>
			<!-- <u-form-item label="邮箱:" class="isshow">
				<u-input input-align="right" v-model="form.email" />
			</u-form-item> -->
			<u-form-item label="住址:" class="isshow">
				<u-input input-align="right" v-model="form.address" />
			</u-form-item>
		</u-form>
		<u-form :model="team_form" ref="team_form" v-else>
			<u-form-item label="班组名称:" label-width='100px' class="isshow">
				<u-input input-align="right" v-model="team_form.team_name"  placeholder="最多输入10个汉字"/>
			</u-form-item>
			<u-form-item label="班组负责人:" label-width='100px' class="isshow">
				<u-input input-align="right" v-model="team_form.team_leader" />
			</u-form-item>
			<u-form-item label="班组类型:" label-width='100px'>
				<u-input input-align="right" v-model="team_form.team_type" type="select" placeholder="请选择" @click="typeshow=true"/>
				<!-- <u-select v-model="typeshow" :list="typeList" @confirm="typeName"></u-select> -->
				<u-picker mode="selector" v-model="typeshow"  :default-selector="[0]" :range="typeList" range-key="label" @confirm="typeName"></u-picker>
			</u-form-item>
			<u-form-item label="隶属劳务公司:" label-width='100px'>  <!-- id -->
				<u-input input-align="right" v-model="team_form.company" type="select" placeholder="请选择" @click="companyshow=true"/>
				<!-- <u-select v-model="companyshow" :list="companyList" @confirm="companyName"></u-select> -->
				<u-picker mode="selector" v-model="companyshow"  :default-selector="[0]" :range="companyList" range-key="label" @confirm="companyName"></u-picker>
			</u-form-item>
			<u-form-item label="成立日期:" label-width='100px'>
				<!-- <u-input input-align="right" v-model="team_form.date"/> -->
				<u-input v-model="team_form.date" input-align="right" placeholder="请选择" type="select"
					@click="date_show=true" />
				<u-calendar v-model="date_show" :mode="mode" @change="change"></u-calendar>
				<!-- <u-picker mode="time" v-model="date_show" @confirm="confirmtime"></u-picker> -->
			</u-form-item>
			<u-form-item label="办公地址:" label-width='100px' class="isshow">
				<!-- <u-input input-align="right" placeholder="请选择" type="select" v-model="team_form.office_address" @click="cityshow=true"/>
				<u-select v-model="cityshow" mode="mutil-column-auto" :list="cityList" @confirm="cityName"></u-select> -->
				<u-input input-align="right" v-model="team_form.office_address"/>
			</u-form-item>
			<u-form-item label="业务范围:" label-width='100px' class="common">
				<!-- <u-input v-model="team_form.business" input-align="right" placeholder="请选择" type="select"
					@click="business_show=true" />
				<u-select v-model="business_show" :list="business_list" @confirm="confirm_business"></u-select> -->
				<u-input v-model="team_form.business" input-align="right" placeholder="请选择" type="select"
					@click="modification_scope(business_list,business_id_list,team_form.business,'业务范围')" />
			</u-form-item>
			<u-form-item label="服务范围:" label-width='100px' class="common">
				<!-- <u-input v-model="team_form.service" input-align="right" placeholder="请选择" type="select" 
					@click="service_show=true" />
				<u-select v-model="service_show" :list="service_list" @confirm="confirm_service" mode="mutil-column-auto"></u-select> -->
				<u-input v-model="team_form.service" input-align="right" placeholder="请选择" type="select"
					@click="modification_scope(service_list,service_id_list,team_form.service,'服务范围')" />
			</u-form-item>
			<u-form-item label="工人数量:" label-width='100px'>  <!-- id -->
				<u-input v-model="team_form.num" input-align="right" placeholder="请选择" type="select"
					@click="num_show=true" />
				<!-- <u-select v-model="num_show" :list="num_list" @confirm="confirm_num"></u-select> -->
				<u-picker mode="selector" v-model="num_show"  :default-selector="[0]" :range="num_list" range-key="label" @confirm="confirm_num"></u-picker>
			</u-form-item>
		</u-form>
		
		<button class="submit" @click="submit">提交审核</button>
	</view>
</template>

<script>
	import api from '@/static/js/api.js'
	
	export default {
		data() {
			return {
				form: {
					type_of_work: '',
					types_of_workers: '',
					working_years: null,
					sex: '男',
					nation: '汉族',
					degree_of_education: '',
					// email:'',
					address: ''
				},
				type_show: false,
				workers_show: false,
				age_show: false,
				sex_show: false,
				nation_show: false,
				education_show: false,
				type_list: [{
						value: '1',
						label: '普通工'
					},
					{
						value: '2',
						label: '辅助工'
					},
					{
						value: '3',
						label: '特种作业人员'
					}
				],
				workers_list:[],
				workers_list1: [{
						label: '木工'
					},
					{
						label: '砌筑工'
					},
					{
						label: '抹灰工'
					},
					{
						label: '钢筋工'
					},
					{
						label: '油漆工'
					},
					{
						label: '防水工'
					},
					{
						label: '模板工'
					},
					{
						label: '筑路工'
					},
					{
						label: '水暖工'
					},
					{
						label: '混凝土工'
					},
					{
						label: '安装工'
					},
					{
						label: '普通工其他'
					}
				],
				workers_list2: [{
						label: '门卫'
					},
					{
						label: '清扫人员'
					},
					{
						label: '仓库管理员'
					},
					{
						label: '技能工辅助'
					},
					{
						label: '辅助工其他'
					}
				],
				workers_list3: [{
						label: '建筑电工'
					},
					{
						label: '建筑焊工（电焊、气焊、切割）'
					},
					{
						label: '建筑起重信号司索工'
					},
					{
						label: '建筑架子工（普通脚手架、附着升降脚手架）'
					},
					{
						label: '建筑起重机械司机（施工升降机）'
					},
					{
						label: '建筑起重机械司机（物料提升机）'
					},
					{
						label: '建筑起重机械司机（塔式起重机）'
					},
					{
						label: '建筑起重机械安装拆卸工（塔式起重机）'
					},
					{
						label: '建筑起重机械安装拆卸工（施工升降机）'
					},
					{
						label: '建筑起重机械安装拆卸工（物料提升机）'
					},
					{
						label: '高处作业吊篮操作工'
					},
					{
						label: '高处作业吊篮安装拆卸工'
					},
					{
						label: '建筑起重机维修工'
					},
					{
						label: '桩工机械操作工'
					},
					{
						label: '混凝土机械操作工'
					},
					{
						label: '钢筋机械连接操作工'
					},
					{
						label: '建筑起重机械安装质量检测工（塔式起重机）'
					},
					{
						label: '建筑起重机械安装质量检测工（施工升降机）'
					},
					{
						label: '建筑施工现场内机动车司机'
					},
					{
						label: '建筑土石方机械操作工（挖掘机）'
					},
					{
						label: '建筑土石方机械操作工（装载机）'
					},
					{
						label: '建筑土石方机械操作工（推土机）'
					},
				],
				sex_list: [{
						value: '1',
						label: '男'
					},
					{
						value: '2',
						label: '女'
					}
				],
				nation_list: [{
						label: '汉族'
					},
					{
						label: '蒙古族'
					},
					{
						label: '彝族'
					},
					{
						label: '侗族'
					},
					{
						label: '哈萨克族'
					},
					{
						label: '畲族'
					},
					{
						label: '纳西族'
					},
					{
						label: '仫佬族'
					},
					{
						label: '仡佬族'
					},
					{
						label: '怒族'
					},
					{
						label: '保安族'
					},
					{
						label: '鄂伦春族'
					},
					{
						label: '回族'
					},
					{
						label: '壮族'
					},
					{
						label: '瑶族'
					},
					{
						label: '傣族'
					},
					{
						label: '高山族'
					},
					{
						label: '景颇族'
					},
					{
						label: '羌族'
					},
					{
						label: '锡伯族'
					},
					{
						label: '乌孜别克族'
					},
					{
						label: '裕固族'
					},
					{
						label: '赫哲族'
					},
					{
						label: '藏族'
					},
					{
						label: '布依族'
					},
					{
						label: '白族'
					},
					{
						label: '黎族'
					},
					{
						label: '拉祜族'
					},
					{
						label: '柯尔克孜族'
					},
					{
						label: '布朗族'
					},
					{
						label: '阿昌族'
					},
					{
						label: '俄罗斯族'
					},
					{
						label: '京族'
					},
					{
						label: '门巴族'
					},
					{
						label: '维吾尔族'
					},
					{
						label: '朝鲜族'
					},
					{
						label: '土家族'
					},
					{
						label: '傈僳族'
					},
					{
						label: '水族'
					},
					{
						label: '土族'
					},
					{
						label: '撒拉族'
					},
					{
						label: '普米族'
					},
					{
						label: '鄂温克族'
					},
					{
						label: '塔塔尔族'
					},
					{
						label: '珞巴族'
					},
					{
						label: '苗族'
					},
					{
						label: '满族'
					},
					{
						label: '哈尼族'
					},
					{
						label: '佤族'
					},
					{
						label: '东乡族'
					},
					{
						label: '达斡尔族'
					},
					{
						label: '毛南族'
					},
					{
						label: '塔吉克族'
					},
					{
						label: '德昂族'
					},
					{
						label: '独龙族'
					},
					{
						label: '基诺族'
					}
				],
				education_list: [
					{
						label: '研究生及以上'
					},
					{
						label: '本科'
					},
					{
						label: '专科'
					},
					{
						label: '高中及以下'
					}
				],
				account_type:'',
				team_form:{
					team_name:'',
					team_leader:'',
					team_type:'',
					company:'',
					date:'',
					office_address:'',
					business:'',
					service:'',
					num:''
				},
				mode: 'date',
				date_show:false,
				business_show:false,
				service_show:false,
				num_show:false,
				business_list:[],
				business_id:[],
				service_list:[],
				service_id:[],
				num_list:[],
				num_id:'',
				cityList:[],
				cityshow:false,
				province_id: '',
				city_id: '',
				area_id: '',
				typeshow:false,
				typeList:[],
				companyshow:false,
				companyList:[],
				team_type_id:'',
				company_id:'',
				newarr:[],//服务
				newarr1:[],//业务
				business_id_list:[],
				service_id_list:[],
			}
		},
		onShow(){
			this.workers_list = this.workers_list1
			var userinfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.account_type = userinfo.account_type
			if(this.account_type=='班组长'){
				this.service_list = []
				this.business_list = []
				this.typeList = []
				this.companyList = []
				this.num_list = []
				this.cityListMethod()
				this.tageMethod()
			}
			this.information()
		},
		methods: {
			modification_scope(e1,e2,e3,e4){
				// console.log(e1);
				e1 = JSON.stringify(e1)
				e2 = JSON.stringify(e2)
				uni.navigateTo({
					url: `/pagesB/mine/worker/modificationScope?p1=${e1}&&p2=${e2}&&p3=${e3}&&p4=${e4}`
				})
			},
			change(e){
				this.team_form.date = e.result
			},
			confirm_business(e){
				this.newarr1.push(e[0].label)
				this.team_form.business = this.newarr1.join('、')
				this.business_id.push(e[0].value)
			},
			confirm_service(e){
				this.newarr.push(e[0].label)
				this.team_form.service = this.newarr.join('、')
				this.service_id.push(e[1].value)
			},
			confirm_num(e){
				// console.log('工人数量',e);
				this.team_form.num = this.num_list[e[0]].label
				this.num_id = this.num_list[e[0]].value
			},
			typeName(e){
				this.team_type_id = this.typeList[e[0]].value
				this.team_form.team_type = this.typeList[e[0]].label
				// console.log(this.team_type_id,this.team_form.team_type);
			},
			companyName(e){
				// console.log('公司',e);
				this.company_id = this.companyList[e[0]].value
				this.team_form.company = this.companyList[e[0]].label
			},
			confirm_type(e) {
				var val = this.type_list[e[0]].label
				var str_workers = JSON.stringify({label:this.form.types_of_workers})
				if(val == '普通工'){
					this.workers_list = this.workers_list1
					if(JSON.stringify(this.workers_list1).indexOf(str_workers)==-1){
						this.form.types_of_workers = '木工'
					}
				}else if(val == '辅助工'){
					this.workers_list = this.workers_list2
					if(JSON.stringify(this.workers_list2).indexOf(str_workers)==-1){
						this.form.types_of_workers = '门卫'
					}
				}else{
					this.workers_list = this.workers_list3
					if(JSON.stringify(this.workers_list3).indexOf(str_workers)==-1){
						this.form.types_of_workers = '建筑电工'
					}
				}
				this.form.type_of_work = val
			},
			confirm_workers(e) {
				var val = this.workers_list[e[0]].label
				const result1 = this.workers_list1.find(v=>v.label==val)
				const result2 = this.workers_list2.find(v=>v.label==val)
				const result3 = this.workers_list3.find(v=>v.label==val)
				if(result1){
					this.workers_list = this.workers_list1
					this.form.type_of_work = '普通工'
				}else if(result2){
					this.workers_list = this.workers_list2
					this.form.type_of_work = '辅助工'
				}else{
					this.workers_list = this.workers_list3
					this.form.type_of_work = '特种作业人员'
				}
				this.form.types_of_workers = val
			},
			confirm_age(e) {
				this.form.working_years = e[0].label
			},
			confirm_sex(e) {
				this.form.sex = this.sex_list[e[0]].label
			},
			confirm_nation(e) {
				this.form.nation = this.nation_list[e[0]].label
			},
			confirm_education(e) {
				this.form.degree_of_education = this.education_list[e[0]].label  
			},
			information(){
				var userInfo = JSON.parse(uni.getStorageSync('userInfo'))
				var uid = userInfo.uid
				var access_token = userInfo.access_token;
				api.personal_information(userInfo.access_token,'res.partner', '_api_get_personal_information', userInfo.uid,userInfo.account_type).then(res=>{
					// console.log(res);
					if(userInfo.account_type=='班组长'){
						this.team_form.business = []
						this.team_form.service = []
						if(this.team_form.team_name==''){
							this.team_form.team_name = res.data.team
						}
						if(this.team_form.team_leader==''){
							this.team_form.team_leader = res.data.team_leader_name
						}
						if(this.team_form.team_type==''){
							this.team_form.team_type = res.data.work_type
						}
						if(this.team_form.company==''){
							this.team_form.company = res.data.company_name
						}
						if(this.team_form.num==''){
							this.team_form.num = res.data.worker
						}
						if(this.team_form.date==''){
							this.team_form.date = res.data.create_date
						}
						if(this.team_form.office_address==''){
							this.team_form.office_address = res.data.office_address
						}
						
						var businessList = []
						this.business_id_list=[]
						res.data.business_ids.forEach(item=>{
							businessList.push(item.name)
							this.business_id_list.push(item.id)
						})
						var serviceList = []
						this.service_id_list = []
						res.data.city_ids.forEach(item=>{
							serviceList.push(item.name)
							this.service_id_list.push(item.id)
						})
						this.team_form.business = businessList.join('、')
						this.team_form.service = serviceList.join('、')
						
						// if(this.team_form.business==''){
						// 	this.team_form.business='暂无'
						// }
						// if(this.team_form.service==''){
						// 	this.team_form.service='暂无'
						// }
					}else{
						type_of_work: '',
						this.form.type_of_work = res.data.work_type_grade
						this.form.types_of_workers = res.data.work_type
						this.form.working_years = res.data.work_years
						this.form.sex = res.data.sex
						this.form.nation = res.data.nation
						this.form.degree_of_education = res.data.education_degree=='空'?'':res.data.education_degree
						this.form.address = res.data.address
						if(this.form.type_of_work=='普通工'){
							this.workers_list = this.workers_list1
						}else if(this.form.type_of_work=='辅助工'){
							this.workers_list = this.workers_list2
						}else{
							this.workers_list = this.workers_list3
						}
					}
				})
			},
			submit() {
				var userInfo = JSON.parse(uni.getStorageSync('userInfo'))
				var uid = userInfo.uid
				var access_token = userInfo.access_token;
				if(this.account_type=='工人'){
					if(this.form.type_of_work==''){
						uni.showToast({
						  title: '请选择工种类型',
						  icon: 'none'
						})
						return
					}
					if(this.form.types_of_workers==''){
						uni.showToast({
						  title: '请选择工种',
						  icon: 'none'
						})
						return
					}
					if(this.form.working_years==''){
						uni.showToast({
						  title: '请填写工龄',
						  icon: 'none'
						})
						return
					}
					if(this.form.degree_of_education==''){
						uni.showToast({
						  title: '请选择文化程度',
						  icon: 'none'
						})
						return
					}
					if(this.form.address==''){
						uni.showToast({
						  title: '请填写地址',
						  icon: 'none'
						})
						return
					}
					api.perfectInformation(access_token,'res.partner','_api_verify_information',uid,
					this.form.type_of_work,
					this.form.types_of_workers,
					this.form.working_years,
					this.form.sex,
					this.form.nation,
					this.form.degree_of_education,
					this.form.address
					).then(res=>{
						if(res.errcode==0){
							uni.navigateBack()
						}
					})
				}else{
					if(this.team_form.team_name==''){
						uni.showToast({
						  title: '请填写班组名称',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.team_name.replace(/[^\x00-\xff]/g, 'xx').length>20){
						uni.showToast({
							title: '班组名称最多10个汉字',
							icon: 'none'
						})
						return
					}
					if(this.team_form.team_leader==''){
						uni.showToast({
						  title: '请选择班组负责人',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.team_type==''){
						uni.showToast({
						  title: '请选择班组类型',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.date==''){
						uni.showToast({
						  title: '请选择成立日期',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.office_address==''){
						uni.showToast({
						  title: '请填写办公地址',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.business==''){
						uni.showToast({
						  title: '请选择业务范围',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.service==''){
						uni.showToast({
						  title: '请选择服务范围',
						  icon: 'none'
						})
						return
					}
					if(this.team_form.num==''){
						uni.showToast({
						  title: '请选择工人数量',
						  icon: 'none'
						})
						return
					}
					
					var business_list = []
					business_list.push(this.team_form.business)
					var team_id = JSON.parse(uni.getStorageSync('userInfo')).team_id
					
					api.information(access_token,'res.partner','_api_verify_information',uid,
					'班组长',
					this.team_form.team_name,
					this.team_form.team_leader,
					this.team_type_id,
					this.company_id,
					this.team_form.date,
					this.team_form.office_address,
					JSON.stringify(this.business_id_list),
					JSON.stringify(this.service_id_list),
					this.num_id,
					team_id
					).then(res=>{
						if(res.errcode==0){
							uni.navigateBack()
						}
					})
				}
			},
			cityListMethod() {
				// api.cityApi('res.country.state', '_api_get_information_in_bulk_area_reverse', JSON.parse(uni.getStorageSync('userInfo')).access_token).then(
				api.cityApi('res.country.state', '_api_get_information_in_bulk_area', JSON.parse(uni.getStorageSync('userInfo')).access_token).then(
					res => {
						// this.cityList = res.data
						this.service_list = res.data
					}).catch(e => {
					uni.showToast({
						icon: 'none',
						title: e.message
					})
				})
			},
			cityName(e) {
				// console.log(e);
				if (e[0].label == e[1].label) {
					this.team_form.office_address = e[0].label + ' ' + e[2].label
				} else {
					this.team_form.office_address = e[0].label + ' ' + e[1].label + ' ' + e[2].label
				}
				this.province_id = e[0].value
				this.city_id = e[1].value
				// console.log(this.city_id);
				this.area_id = e[2].value
			},
			tageMethod() {
				api.cityApi('res.country.state', '_api_get_information_in_bulk_area_reverse', JSON.parse(uni.getStorageSync('userInfo')).access_token)
					.then(
						res => {
							// console.log(res);
							var objData = res.data.tag
							for (let key in objData) {
								var obj = {}
								obj.value = objData[key]
								obj.label = key
								this.typeList.push(obj)
							}
							var objData1 = res.data.company
							for (let key in objData1) {
								var obj = {}
								obj.value = objData1[key]
								obj.label = key
								this.companyList.push(obj)
							}
							var objData2 = res.data.business
							for (let key in objData2) {
								var obj = {}
								obj.value = objData2[key]
								obj.label = key
								this.business_list.push(obj)
							}
							var objData3 = res.data.worker
							for (let key in objData3) {
								var obj = {}
								obj.value = objData3[key]
								obj.label = key
								this.num_list.push(obj)
							}
							// this.typeList = res.data.tag
							// this.companyList = res.data.company
						}).catch(e => {
						uni.showToast({
							icon: 'none',
							title: e.message
						})
					})
			},
		}
	}
</script>

<style lang="less" scoped>
	.information {
		height: 100vh;
		background: #EBEEF5;

		.submit {
			background: #D73C4B;
			color: #fff;
			width: 40%;
			margin-top: 20rpx;
			height: 60rpx;
			font-size: 28rpx;
			line-height: 60rpx;
		}
		// /deep/.u-input__right-icon{
		// 	display: none;
		// }
		/deep/.u-form{
			padding: 0 20rpx;
			background: #fff!important;
		}
		/deep/.u-form-item::after{
			border: none;
		}
		/deep/.u-icon__icon::before{
			content: "\e605";
		}
		/deep/.isshow .u-input__right-icon{
			display: none;
		}
		/deep/.common .u-input__input{
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
	/deep/.u-icon text{
		color: #c0c4cc!important;
	}
	/deep/.u-calendar .u-calendar__action .u-calendar__action__icon:nth-child(1) .u-icon text::before{
		content: "\e68c"!important;
	}
	/deep/.u-calendar .u-calendar__action .u-calendar__action__icon:nth-child(2) .u-icon text::before{
		content: "\e60e"!important;
	}
	/deep/.u-calendar .u-calendar__action .u-calendar__action__icon:nth-child(5) .u-icon text::before{
		content: "\e68d"!important;
	}
</style>
